package com.tring.ysyn.util.transcation;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronizationManager;

/**
 * @author Tring
 * date 2022-11-11
 */
public class TranscationUtils {

    public static void doAfterTransact(Runnable runnable){
        //判断下我们上下文有没有事务激活，如果有就就把DoTransactionCompletion注册进去
        if (TransactionSynchronizationManager.isActualTransactionActive()){
            TransactionSynchronizationManager.registerSynchronization(new DoTransactionCompletion(runnable));
        }
    }

    /**
     *测试
     */
    @Transactional
    public void daTx(){
        //start tx
        TranscationUtils.doAfterTransact(()->{
            //semg MQ

        });

        //end tx
    }
}
